
package com.suarte.core.hibernate;
import com.suarte.core.Currency;
import com.suarte.core.dao.CurrencyDao;

import java.util.List;

import org.appfuse.dao.hibernate.GenericDaoHibernate;

import org.springframework.stereotype.Repository;

/**
 * @date   Mar 09, 2011
 * @author Gcastillo
 */
@Repository("currencyDao")
public class CurrencyDaoHibernate extends GenericDaoHibernate<Currency, Long> implements CurrencyDao {

    public CurrencyDaoHibernate() {
        super(Currency.class);
    }

    public List<Currency> findByDescription(String description) {
        return getHibernateTemplate().find("from Currency where description = ?", description);
    }

    public List<Currency> findBySymbol(String symbol) {
        return getHibernateTemplate().find("from Currency this where this.symbol = ?", symbol);
    }

    public Currency findLocal() {
        List list = getHibernateTemplate().find("from Currency this where this.local = true");
        return list != null ? (Currency)list.get(0) : null;
    }

    public Currency findSystemDefault() {
        List list = getHibernateTemplate().find("from Currency this where this.systemDefault = true");
        return list != null ? (Currency)list.get(0) : null;
    }

    public List<Currency> findAllButLocal() {
        return getHibernateTemplate().find("from Currency this where this.local = false");
    }
}